package com.zretc.emptraining.serviceimpl;

import java.util.List;

import com.zretc.emptraining.dao.CourseDao;
import com.zretc.emptraining.daoimpl.CourseDaoImpl;
import com.zretc.emptraining.dbtools.PageData;
import com.zretc.emptraining.entity.Course;
import com.zretc.emptraining.service.CourseService;

/**
 * 课程service实现类
 * 
 * @author 傅洁敏
 *
 */
public class CourseServiceImpl implements CourseService {

	CourseDao cd = new CourseDaoImpl();

	/**
	 * 增加课程(课程名不重复)
	 */
	@Override
	public boolean addCourse(Course course) {
		if (course == null) {
			return false;
		}
		if (cd.getCourseByName(course.getCourseName()) != null) {
			return false;
		}
		return cd.addCourse(course);
	}

	/**
	 * 删除课程
	 */
	@Override
	public boolean delCourse(int courseNo) {
		// TODO Auto-generated method stub
		return cd.delCourse(courseNo);
	}

	/**
	 * 修改课程
	 */
	@Override
	public boolean updCourse(Course course) {
		if (course == null) {
			return false;
		}
		return cd.updCourse(course);
	}

	/**
	 * 分页：根据 课程名关键字 模糊查询
	 */
	@Override
	public PageData<Course> getCoursesByPage(int page, int pageSize, String keywords) {
		// 避免用户输入页码小于1
		if (page < 1) {
			page = 1;
		}
		return cd.getCoursesByPage(page, pageSize, keywords);
	}
/**
 * 根据课程名精确查询
 */
	@Override
	public Course getCourseByName(String courseName) {
		// TODO Auto-generated method stub
		return cd.getCourseByName(courseName);
	}
/**
 * 查询所有课程信息
 */
	@Override
	public List<Course> getAllCourses() {
		// TODO Auto-generated method stub
		return cd.getAllCourses();
	}


}
